﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebNext.UI.Models.Tags;
using System.Collections.Specialized;
using WebNext.UI.Models.Admin;

namespace WebNext.UI.Utils.ModelBinders
{
	public class AdminSettingsModelBinder : IModelBinder
	{
		public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
		{
			if (bindingContext.Model != null)
			{
				throw new NotImplementedException("Cannot update instances");
			}
			return this.BindTagModel(controllerContext.HttpContext.Request.Form);
		}

		private AdminSettingsViewModel BindTagModel(NameValueCollection form)
		{
			string userName = form["userName"];
			string email = form["email"];
			string password = form["password"];
			string repeatedPassword = form["repeatedPassword"];
			return new AdminSettingsViewModel(userName, email, password, repeatedPassword);
		}
	}
}